Skip to content

Feature/visa tests#32

Merged
eeebbaandersson merged 3 commits into
mainfrom
feature/visa-tests
Apr 16, 2026
Merged

Feature/visa tests#32
eeebbaandersson merged 3 commits into
mainfrom
feature/visa-tests

Conversation

@eeebbaandersson

@eeebbaandersson eeebbaandersson commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Fixed comment display on visa details page to correctly render comment text.

- Added H2 database dependency for in-memory testing.
- Configured application-test.properties for the test environment.
- Converted selected unit tests to integration tests
- Add JpaConfig for auditing and persistence settings
- Add dependency for H2 database
- Implement DataInitializer to seed the database with user test data
- Implement test suite for VisaViewController
@coderabbitai

coderabbitai Bot commented Apr 15, 2026

Copy link
Copy Markdown

Warning

Rate limit exceeded

@eeebbaandersson has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 45 minutes and 38 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 45 minutes and 38 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2adeedfd-df9d-4073-b80e-4ea7f717476c

📥 Commits

Reviewing files that changed from the base of the PR and between ca962ad and b73dc79.

📒 Files selected for processing (2)
  • pom.xml
  • src/test/java/org/example/visacasemanagementsystem/visa/VisaServiceIntegrationTest.java
📝 Walkthrough

Walkthrough

The PR refactors Spring application startup by extracting JPA auditing and data initialization into dedicated configuration classes, introduces H2 in-memory database for testing with test-specific configuration, converts unit tests to integration tests backed by a real database, expands test coverage with comprehensive controller tests, and corrects a template property reference.

Changes

Cohort / File(s) Summary
Build & Dependencies
pom.xml
Added H2 database dependency with runtime scope for test support.
Spring Configuration
src/main/java/org/example/visacasemanagementsystem/VisaCaseManagementSystemApplication.java, src/main/java/org/example/visacasemanagementsystem/config/JpaConfig.java, src/main/java/org/example/visacasemanagementsystem/config/DataInitializer.java
Moved @EnableJpaAuditing from application class to dedicated JpaConfig class; extracted CommandLineRunner initData bean from application class to new DataInitializer configuration class for cleaner separation of concerns.
Test Infrastructure
src/test/resources/application-test.properties
Added test profile configuration for in-memory H2 database setup, including datasource credentials, Hibernate dialect settings, schema auto-creation/drop, and Flyway migration disablement.
Visa Service Tests
src/test/java/org/example/visacasemanagementsystem/visa/VisaServiceTest.java, src/test/java/org/example/visacasemanagementsystem/visa/VisaServiceIntegrationTest.java
Removed three mocked unit tests (applyForVisa, updateVisa, assignHandler) from VisaServiceTest; added equivalent integration tests in new VisaServiceIntegrationTest class that exercise workflows against a real database, validating audit logging alongside persistence.
Controller Tests
src/test/java/org/example/visacasemanagementsystem/visa/VisaViewControllerTest.java
Added comprehensive Web MVC test suite covering dashboard views (admin vs. user filtering), visa application submission (valid/invalid data handling), edit form access and updates with authorization checks, admin actions (approve, assign, request info, reject), and visa details view with role-based access control.
Template Fix
src/main/resources/templates/visa/details.html
Corrected Thymeleaf expression for comment rendering from comment.content to comment.text to match actual entity property name.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • Feature/visa view controller #27: Introduced the initial CommandLineRunner initData bean in the application class; this PR refactors that bean into a separate DataInitializer configuration class alongside a new JpaConfig class.

Poem

🐰 Configs spring to life, separated and bright,
Data hops to its own class with delight,
H2 databases multiply like rabbits in test,
Integration flows put the logic to the test,
One little text fix, and all's set right!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Feature/visa tests' is vague and generic, using a branch-naming convention rather than describing the actual changes made in the pull request. Use a descriptive title that summarizes the main change, such as 'Add integration and controller tests for visa workflows' or 'Refactor data initialization and add comprehensive visa tests'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/visa-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/test/java/org/example/visacasemanagementsystem/visa/VisaServiceIntegrationTest.java (1)

41-43: Remove redundant save() call.

createAndSaveValidUser() already persists the user (line 156), so the second save() at line 43 is unnecessary.

♻️ Proposed fix
        // Arrange
        User user = createAndSaveValidUser();
-
-       user = userRepository.save(user);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/test/java/org/example/visacasemanagementsystem/visa/VisaServiceIntegrationTest.java`
around lines 41 - 43, The test calls createAndSaveValidUser() which already
persists and returns the saved User, so remove the redundant
userRepository.save(user) call: keep the User user = createAndSaveValidUser();
assignment and delete the subsequent user = userRepository.save(user); reference
createAndSaveValidUser() and userRepository.save(...) to locate and remove the
extra persistence step.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pom.xml`:
- Around line 157-161: The H2 dependency is currently declared with scope
"runtime" which makes it available in production; update the <dependency> for
com.h2database:h2 in the pom.xml to use scope "test" instead of "runtime" so H2
is only on the test classpath (locate the dependency block containing groupId
com.h2database and artifactId h2 and change its <scope> element to test).

In
`@src/main/java/org/example/visacasemanagementsystem/config/DataInitializer.java`:
- Around line 17-33: Fix the admin email typo and ensure ADMIN creation is
independent of USER existence: change the admin.setEmail("user@test.com2") to a
proper distinct admin address (e.g., "admin@test.com" or similar) and move the
ADMIN creation logic out of the block guarded by
userRepository.findByEmail("user@test.com").isEmpty(); instead, check
userRepository.findByEmail("admin@test.com").isEmpty() (or the chosen admin
email) and create/save the admin user (the User admin object and
admin.setUserAuthorization(UserAuthorization.ADMIN) /
userRepository.save(admin)) in its own conditional so ADMIN is created when
missing regardless of USER presence.

---

Nitpick comments:
In
`@src/test/java/org/example/visacasemanagementsystem/visa/VisaServiceIntegrationTest.java`:
- Around line 41-43: The test calls createAndSaveValidUser() which already
persists and returns the saved User, so remove the redundant
userRepository.save(user) call: keep the User user = createAndSaveValidUser();
assignment and delete the subsequent user = userRepository.save(user); reference
createAndSaveValidUser() and userRepository.save(...) to locate and remove the
extra persistence step.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 890aad37-b8cb-4d1e-9a2b-5ab9e931f156

📥 Commits

Reviewing files that changed from the base of the PR and between 4c9363c and ca962ad.

📒 Files selected for processing (9)
  • pom.xml
  • src/main/java/org/example/visacasemanagementsystem/VisaCaseManagementSystemApplication.java
  • src/main/java/org/example/visacasemanagementsystem/config/DataInitializer.java
  • src/main/java/org/example/visacasemanagementsystem/config/JpaConfig.java
  • src/main/resources/templates/visa/details.html
  • src/test/java/org/example/visacasemanagementsystem/visa/VisaServiceIntegrationTest.java
  • src/test/java/org/example/visacasemanagementsystem/visa/VisaServiceTest.java
  • src/test/java/org/example/visacasemanagementsystem/visa/VisaViewControllerTest.java
  • src/test/resources/application-test.properties
💤 Files with no reviewable changes (2)
  • src/main/java/org/example/visacasemanagementsystem/VisaCaseManagementSystemApplication.java
  • src/test/java/org/example/visacasemanagementsystem/visa/VisaServiceTest.java

Comment thread pom.xml
Comment on lines +17 to +33
if (userRepository.findByEmail("user@test.com").isEmpty()) {
User user = new User();
user.setFullName("USER");
user.setEmail("user@test.com");
user.setPassword("password");
user.setUserAuthorization(UserAuthorization.USER);
userRepository.save(user);
System.out.println("Testanvändare skapad med ID: " + user.getId());

User admin = new User();
admin.setFullName("ADMIN");
admin.setEmail("user@test.com2");
admin.setPassword("password");
admin.setUserAuthorization(UserAuthorization.ADMIN);
userRepository.save(admin);
System.out.println("Test-admin skapad med ID: " + admin.getId());
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Fix typo in admin email and restructure initialization logic.

Two issues:

  1. Line 28: Email "user@test.com2" appears to be a typo—should likely be something like "admin@test.com2" or a distinct admin email.
  2. The ADMIN user creation (lines 26-32) is nested inside the USER check block, so it only runs when the USER doesn't exist. If the USER already exists but the ADMIN doesn't, the ADMIN won't be created.
🔧 Proposed fix
         if (userRepository.findByEmail("user@test.com").isEmpty()) {
             User user = new User();
             user.setFullName("USER");
             user.setEmail("user@test.com");
             user.setPassword("password");
             user.setUserAuthorization(UserAuthorization.USER);
             userRepository.save(user);
             System.out.println("Testanvändare skapad med ID: " + user.getId());
+        }
 
+        if (userRepository.findByEmail("admin@test.com2").isEmpty()) {
             User admin = new User();
             admin.setFullName("ADMIN");
-            admin.setEmail("user@test.com2");
+            admin.setEmail("admin@test.com2");
             admin.setPassword("password");
             admin.setUserAuthorization(UserAuthorization.ADMIN);
             userRepository.save(admin);
             System.out.println("Test-admin skapad med ID: " + admin.getId());
         }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (userRepository.findByEmail("user@test.com").isEmpty()) {
User user = new User();
user.setFullName("USER");
user.setEmail("user@test.com");
user.setPassword("password");
user.setUserAuthorization(UserAuthorization.USER);
userRepository.save(user);
System.out.println("Testanvändare skapad med ID: " + user.getId());
User admin = new User();
admin.setFullName("ADMIN");
admin.setEmail("user@test.com2");
admin.setPassword("password");
admin.setUserAuthorization(UserAuthorization.ADMIN);
userRepository.save(admin);
System.out.println("Test-admin skapad med ID: " + admin.getId());
}
if (userRepository.findByEmail("user@test.com").isEmpty()) {
User user = new User();
user.setFullName("USER");
user.setEmail("user@test.com");
user.setPassword("password");
user.setUserAuthorization(UserAuthorization.USER);
userRepository.save(user);
System.out.println("Testanvändare skapad med ID: " + user.getId());
}
if (userRepository.findByEmail("admin@test.com2").isEmpty()) {
User admin = new User();
admin.setFullName("ADMIN");
admin.setEmail("admin@test.com2");
admin.setPassword("password");
admin.setUserAuthorization(UserAuthorization.ADMIN);
userRepository.save(admin);
System.out.println("Test-admin skapad med ID: " + admin.getId());
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/org/example/visacasemanagementsystem/config/DataInitializer.java`
around lines 17 - 33, Fix the admin email typo and ensure ADMIN creation is
independent of USER existence: change the admin.setEmail("user@test.com2") to a
proper distinct admin address (e.g., "admin@test.com" or similar) and move the
ADMIN creation logic out of the block guarded by
userRepository.findByEmail("user@test.com").isEmpty(); instead, check
userRepository.findByEmail("admin@test.com").isEmpty() (or the chosen admin
email) and create/save the admin user (the User admin object and
admin.setUserAuthorization(UserAuthorization.ADMIN) /
userRepository.save(admin)) in its own conditional so ADMIN is created when
missing regardless of USER presence.

@eeebbaandersson
eeebbaandersson merged commit 6d575bb into main Apr 16, 2026
2 checks passed
This was referenced Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create testdata for the application using a DataInitializer Add tests for Visa package

1 participant